using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;

namespace StupidSpaceThing
{
	internal abstract class FactionEntity
	{
		protected float massModifier = 1;
		public float Mass { 
			get {
				if( entity.ColObject == null ) return 0;
				return entity.ColObject.Body.Mass * massModifier; 
			} 
		}
		public AudioEmitter AudioEmitter = new AudioEmitter();

		public Faction Faction;		
		protected Entity entity;
		public Entity Entity { get { return entity; } }
		public Vector3 Position { 
			get { 
				return entity.Position; 
			}
			set {
				if( Collision ) {
					entity.ColObject.Body.Position = new Vector2(value.X, value.Z);
				}
				entity.Position = value;
			}
		}
		public Vector2 Position2D { get { return entity.Position2D; } }
		public bool Dead { get { return entity.Dead && entity.ScaleFactor == 0; } }		
		public bool Entered = true;
		public bool Collision { get { return entity.ColObject != null; } }
		public bool BodyEnabled {
			get { return entity.ColObject.Body.Enabled; }
			set { entity.ColObject.Body.Enabled = value; }
		}
		public static int _ProductionTime = 10000;
		public static int _ProductionCost = 1000;
		public virtual int ProductionTime { get { return _ProductionTime; } }
		public virtual int ProductionCost { get { return _ProductionCost; } }
		public bool Built { get { return Entity.ScaleFactor == 1; } }

		public FactionEntity Target = null;

		public FactionEntity(Entity entity) {
			this.entity = entity;
			Entity.FactionEntity = this;
			AudioEmitter = new AudioEmitter();
			AudioEmitter.Position = entity.Position;			
		}

		public virtual void Enter() {
			Entered = true;
			if( Collision ) {
				Entity.ColObject.Body.ClearForce();
				Entity.ColObject.UpdateBodyPosition();
				BodyEnabled = true;
			}
		}

		public virtual void Update(RealGameTime gameTime) {
			if( entity.Dead ) {
				entity.ScaleFactor -= 0.05f;
			}
			if( Collision && BodyEnabled ) {
				Game1.CurMap.Bomb(gameTime, Position2D, (entity.ColObject.Body.Mass * massModifier) / 20, this);
			}
		}

		public virtual void Die() {

		}
	}
}
